package com.testfileupload.uploadimg.design.combination;

import java.util.ArrayList;

public class Client {
    public static void main(String[] args) {
        //产生根节点
        IRoot ceo = new Root("王大麻子", "总经理", 100000);
        //三个部门经理
        IBranch developDep = new Branch("刘da", "研发部门经理", 10000);
        IBranch salesDep = new Branch("马二", "销售经理", 20000);
        IBranch finaceDep = new Branch("赵三", "财务经理", 30000);
        //开发小组长
        IBranch firstBranchGroup = new Branch("杨三", "开发一组组长", 5000);
        IBranch secondBranchGroup = new Branch("武大", "开发二组组长", 6000);

        //小兵
        ILeaf a = new Leaf("a", "开发", 3999);
        ILeaf b = new Leaf("b", "开发", 3999);
        ILeaf c = new Leaf("c", "开发", 3999);
        ILeaf d = new Leaf("d", "销售", 2999);
        ILeaf e = new Leaf("e", "销售", 2000);
        ILeaf f = new Leaf("f", "财务", 1999);
        ILeaf k = new Leaf("k", "秘书", 7999);
        ILeaf g = new Leaf("g", "研发副总", 9999);

        ceo.add(developDep);
        ceo.add(salesDep);
        ceo.add(finaceDep);
        ceo.add(k);
        developDep.add(firstBranchGroup);
        developDep.add(secondBranchGroup);
        developDep.add(g);
        firstBranchGroup.add(a);
        firstBranchGroup.add(b);
        secondBranchGroup.add(c);

        salesDep.add(d);
        salesDep.add(e);

        finaceDep.add(f);

        System.out.println(ceo.getInfo());

        getAllSubordinateInfo(ceo.getSubordinateInfo());

    }

    private static void getAllSubordinateInfo(ArrayList subordinateInfo) {
        int length = subordinateInfo.size();
        for (int i = 0; i < length; i++) {
            Object o = subordinateInfo.get(i);
            if (o instanceof Leaf) {
                ILeaf leaf = (ILeaf) o;
                System.out.println(leaf.getInfo());
            } else {
                IBranch branch = (IBranch) o;
                System.out.println(branch.getInfo());
                getAllSubordinateInfo(branch.getSubordinateInfo());
            }
        }

    }
}
